package vn.sunnet.backviet01.game.coloa.animated.skill;

import org.anddev.andengine.entity.sprite.BaseSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

public class SkillLieuNguyenHoa extends AnimatedSkill{
	private static final long[] duration = { 250, 100, 100, 100, 100, 100,
			100, 5000 };
	public static final String TAG_LNH = "Lieu nguyen hoa";
	
	private boolean isTrans = false;
	private boolean isAttak = false;
	private boolean isCheck = false;
	
	private float damage = 0;
	private float useMana = 0;
	
	private long start = 0;
	
	public SkillLieuNguyenHoa(int name, float pX, float pY,
			TiledTextureRegion pTiledTextureRegion) {
		super(name, pX, pY, pTiledTextureRegion);
		this.setPosition(pX - 510, pY - 510);
		this.animate(duration);
		start = System.currentTimeMillis();
	}

	public void onManagedUpdate(float pSecondsElapsed) {
		if (this.getCurrentTileIndex() > 0 && this.getCurrentTileIndex() < 6 ) {
			if (!isCheck) {
				isAttak = true;
				isCheck = true;
			}
		} 
		else if (this.getCurrentTileIndex() == 7) {
			if (this.getAlpha() > 0.05)
				this.setAlpha(getAlpha() - 0.002f);
			if (!isTrans) {
				isTrans = true;
				this.setZIndex(0);
			}
		}
		
		super.onManagedUpdate(pSecondsElapsed);
	}

	@Override
	public boolean attack(final float pX, final float pY) {
		float xOffset = this.xGoal - pX;
		float yOffset = this.yGoal - pY;
		
		float offset = (float)(Math.sqrt(xOffset * xOffset + yOffset * yOffset));
		
		if (offset < 100 + this.mLevel * 5)
			return true;
		
		return false;
	}

	@Override
	public void complete() {
		
	}

	@Override
	public int getName() {
		return this.name;
	}

	@Override
	public boolean isAttack() {
		return isAttak;
	}

	public void stopInfluence() {
		this.isAttak = false;
	}

	@Override
	public float getDamge() {
		return damage;
	}

	@Override
	public void setDamage(float damage) {
		this.damage = damage;
	}

	@Override
	public float useMana() {
		return useMana;
	}

	@Override
	public void setMana(float mana) {
		this.useMana = mana;
		this.setIgnoreUpdate(false);
	}

	@Override
	public long getStart() {
		// TODO Auto-generated method stub
		return start;
	}

	@Override
	public void remove() {
		detachSelf();
	}

	@Override
	public BaseSprite returnSeft() {
		// TODO Auto-generated method stub
		return this;
	}
	
}
